<?php

namespace common\models\business;

use Yii;

/**
 * This is the model class for table "business_user_scorerecord".
 *
 * @property string $id
 * @property integer $userid
 * @property integer $score
 * @property integer $createtime
 * @property string $remark
 */
class BusinessUserScorerecord extends \yii\db\ActiveRecord
{


    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '积分记录',      //用于修改了什么的显示
        'mainfield' => 'id',      //主要的显示标题的字段
        'picturefield' => [],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>[],      //不需要记录的字段
    ];



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'business_user_scorerecord';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['userid', 'score', 'createtime', 'remark'], 'required'],
            [['userid', 'score', 'createtime'], 'integer'],
            [['remark'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'userid' => '用户',
            'score' => '积分',
            'createtime' => '时间',
            'remark' => '积分操作',
        ];
    }


    /**
     * 积分的操作
     */
    public static function opScore($userid,$score,$remark)
    {
        $data = [
            'userid' => $userid,
            'score' => $score,
            'createtime' => time(),
            'remark' => $remark
        ];

        $res = Yii::$app->db->createCommand()->insert(self::tableName(),$data)->execute();
        if($res !== false){
            return true;
        }
        return false;
    }



}
